#include "favoritebox.h"
#include "ui_favoritebox.h"
#include <QDebug>
FavoriteBox::FavoriteBox(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FavoriteBox)
{
    useroc=FriendListLib::getInstance()->getUserOC();
    ui->setupUi(this);
}

FavoriteBox::~FavoriteBox()
{
    delete ui;
}

void FavoriteBox::setFileName(QString filename)
{
    if(filename[0]=='*')
    {
        this->filename=filename.mid(1);
        setFilePath("./FavoriteFile/"+useroc+"/"+this->filename);
    }
    else
        this->filename=filename;

    ui->label->setText(this->filename);
    QPixmap img(this->filename);
    if(!img.isNull())
    {
        ui->label_4->setPixmap(img);
    }
}

void FavoriteBox::setSenderName(QString sendername)
{
    ui->label_2->setText(sendername);
}

void FavoriteBox::setSendTime(QString time)
{
    ui->label_3->setText(time);
}

QSize FavoriteBox::getSize()
{
    return this->sizeHint();
}

void FavoriteBox::setFileIcon(QPixmap icon)
{
    ui->label_4->setPixmap(icon);
}


QString FavoriteBox::getFileName()
{
    return ui->label->text();
}

QString FavoriteBox::getFilePath()
{
    return filepath;
}

void FavoriteBox::setFilePath(QString path)
{
    filepath=path;
}

void FavoriteBox::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        QFileInfo fileinfo(filepath);
        QDesktopServices::openUrl(fileinfo.absoluteFilePath());
    }
    QWidget::mousePressEvent(event);
}


